<?php
// +----------------------------------------------------------------------
// | APP前台-会员中心
// +----------------------------------------------------------------------
namespace app\webapp\controller;
use app\webapp\model\User as UserModel;
use Session;

class Userface extends Base {

	public function _initialize() {
		parent::_initialize();
	}

	/**
	 * [add_face_student 添加用户对应的画像(学生或学生家长属性)]
	 */
	public function add_face(){
        if(!$this->isLogin()) {
          return json(['code'=>403,'message'=>'你还没有登录']);
        }
        $user = $this->getLoginUser();
        $data = [
			'user_id' => $user["id"],
			'face_id' => 1,
			'name'    => trim(input('post.name/s')),
			'work'    => trim(input('post.work/s')),
			'phone'   => trim(input('post.phone/s')),
		];
        $validate = $this->validate($data,'Userface.add');
        if(true !== $validate){
            return json(['code'=>1,'message'=>$validate]);
		}
        if($data['work'] == '0'){
            return json(['code'=>1,'message'=>'请选择参数单位']);
		}
        $result = model('Userface')->add_student_user($data);
		if(!$result){
			return json(['code'=>1,'message'=>'提交失败,请重试']);
		}else{
			return json(['code'=>0,'message'=>'提交成功,请开始竞赛']);
		}
	}
}
